package com.zut.dao;

import com.zut.domain.Admin;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdminDao {
    @Results(id = "groupWithAdmin",
            value = {
                    @Result(property = "id", column = "admin_id", id = true),
                    @Result(property = "password", column = "admin_password"),
                    @Result(property = "name", column = "admin_name"),
            })
    @Select("select * from admin where admin_id=#{id} and admin_password=#{password}")
    Admin getByNP(Admin admin);

    @Update("<script>                                                                        "
            + "update admin                                                                  "
            + "<set>                                                                         "
            + "  <if test='password != null'> admin_password=#{password},               </if>"
            + "  <if test='name != null'> admin_name=#{name},                           </if>"
            + "</set>                                                                        "
            + "where admin_id = #{id}                                                        "
            + "</script>                                                                     ")
    int update(Admin admin);

    @Select("select admin_password from admin where admin_id = #{id}")
    String getPassword(String id);
}
